package com.ss.android.download;

import android.content.ContentUris;
import android.database.Cursor;
import android.database.sqlite.SQLiteException;
import android.util.Log;

final class s extends Thread {
    private final r a;

    s(r arg1) {
        this.a = arg1;
    }

    public final void run() {
        int v0_3;
        Cursor v1 = null;
        Cursor v6 = null;
        this.a.b();
        r v7 = this.a;
        if (com.ss.android.download.aa.c) {
            Log.i("SsDownloadManager", "in trimDatabase");
        }

        try {
            v1 = k.a(v7.c).a(com.ss.android.download.a.a.a, new String[]{"_id"}, "status >= \'200\'", null, "lastmod");
            if (v1 != null) {
                if (v1.moveToFirst()) {
                    v0_3 = v1.getCount() - 1000;
                    int v2 = v1.getColumnIndexOrThrow("_id");
                    while (true) {
                        label_34:
                        if (v0_3 > 0) {
                            k.a(v7.c).a(ContentUris.withAppendedId(com.ss.android.download.a.a.a, v1.getLong(v2)));
                            if (v1.moveToNext()) {
                                --v0_3;
                                continue;
                            }
                        }
                        break;
                    }
                }
                return;
            }
            Log.e("SsDownloadManager", "null cursor in trimDatabase");
            if (v1 == null) {
                return;
            }
        } catch (SQLiteException v0_1) {
            v1 = v6;
            Log.w("SsDownloadManager", "trimDatabase failed with exception: " + v0_1.getMessage());
            if (v1 != null) {
            } else {
                return;
            }
        } finally {
            try {
                v1.close();
            } catch (Exception e) {

            }
        }

    }
}

